######################################
#
#
######################################

#target you can change test to what you want
#静态库文件名，lib*.a
TARGET  := libtest.a

#compile and lib parameter
#编译参数
CC      := g++
AR      = ar
RANLIB  = ranlib
LIBS    :=
LDFLAGS :=
DEFINES :=
INCLUDE := -I.
CFLAGS  := -g -Wall -O3 $(DEFINES) $(INCLUDE)
CXXFLAGS:= $(CFLAGS) -DHAVE_CONFIG_H
  
#i think you should not fix anything here
#下面的基本上不需要做任何改动了

#source file
#源文件，自动找所有.c和.cpp文件，并将目标定义为同名.o文件
SOURCE  := $(wildcard *.c) $(wildcard *.cpp)
OBJS    := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SOURCE)))
#头文件，自动查找.h文件
HEADER := $(wildcard *.h)

.PHONY : everything objs clean veryclean rebuild install

everything : $(TARGET)

all : $(TARGET)

objs : $(OBJS)

rebuild: veryclean everything
             
clean :
	rm -fr $(OBJS)

veryclean : clean
	rm -fr $(TARGET)

install :
	test -f ./sample/lib && echo ' ' || mkdir -p ./sample/lib
	cp $(TARGET) ./sample/lib/
	test -f ./sample/include/ && echo ' ' || mkdir -p ./sample/include
	cp $(HEADER) ./sample/include/

$(TARGET) : $(OBJS)
	$(AR) cru $(TARGET) $(OBJS)
	$(RANLIB) $(TARGET)